package Pages;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;

//Base case: Guest Page 封装了访客、咨询师、督导管理的搜索、禁用和启用以及确定/取消的操作。
//由ConsultantPage.SupervisorPage继承

public class GuestPage extends HomePage {
    //搜索方法，返回字符串
    public String getSearchRes(String keys){
        clickInput().search(keys).enter();
        waitForWindow(2000);
        WebElement element = driver.findElement(By.cssSelector(".el-table__body"));
        String info = element.getText();
        return info;
    }
    //点击搜索框
    public GuestPage clickInput(){
        driver.findElement(By.cssSelector(".el-input:nth-child(2) > .el-input__inner")).click();
        return this;
    }
    //模糊搜索
    public GuestPage search(String keys){
        driver.findElement(By.cssSelector(".el-input:nth-child(2) > .el-input__inner")).sendKeys(keys);
        return this;
    }

    //回车
    public GuestPage enter(){
        driver.findElement(By.cssSelector(".el-input:nth-child(2) > .el-input__inner")).sendKeys(Keys.ENTER);
        return this;
    }

    //禁用
    public GuestPage disable(){
        waitForWindow(2000);
        driver.findElement(By.xpath("//span[contains(.,'禁用')]")).click();
        return this;
    }

    //启用
    public GuestPage enable(){
        waitForWindow(2000);
        driver.findElement(By.xpath("//span[contains(.,'启用')]")).click();
        //driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(8) > div:nth-child(1) > div:nth-child(1) > button:nth-child(3)")).click();
        return this;
    }

    //确定
    public GuestPage confirm(){
        driver.findElement(By.xpath("//button[contains(.,'确定')]")).click();
        return this;
    }

    //取消
    public GuestPage cancel(){
        driver.findElement(By.xpath("//button[contains(.,'取消')]")).click();
        return this;
    }

    //获得访客/咨询师/督导的状态
    public String getState(){
        waitForWindow(2000);
        //默认是第一个用户的状态
        WebElement element =  driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(9) > div:nth-child(1)"));
        //tr.el-table__row:nth-child(1) > td:nth-child(7) > div:nth-child(1)
        return element.getText();
    }

    //点击修改排班button
    public GuestPage editSchedule(){
        driver.findElement(By.xpath("//button[contains(.,'修改排班')]")).click();
        return this;
    }

    //选择周值班天数
    public GuestPage pickDay(String day){
       driver.findElement(By.cssSelector(".arrangementRow > .el-button:nth-child("+day+")")).click();
       return this;
    }

}
